/*
 * Tuple.java
 *
 * Created on June 27, 2006, 12:45 PM
 *
 */

package galronnlp.util;

/**
 *
 * @author Daniel A. Galron
 */
public class Tuple implements Comparable{
    
    protected Object[] array;
    
    public Tuple(int n) {
        array = new Object[n];
    }
    
    public Object get(int i) {
        return array[i];
    }
    
    public void put(int i, Object o) {
        array[i] = o;
    }
    
    public int hashCode() {
        return this.array.length * this.array[0].hashCode();
    }
    
    public boolean equals(Object o) {
        Tuple other = (Tuple)o;
        boolean ret = false;
        if(array.length == other.array.length) {
            ret = true;
            for(int i = 0; i < array.length; i++) {
                ret &= this.array[i].equals(other.array[i]);
            }
        }
        return ret;
    }
    
    public int compareTo(Object o) {
        Tuple other = (Tuple)o;
        if(this.array.length == 0 && other.array.length == 0)
            return 0;
        else if(this.array.length > 0 && other.array.length == 0)
            return 1;
        else if(this.array.length == 0 && other.array.length > 0)
            return -1;
        else
            return ((Comparable)this.get(0)).compareTo((Comparable)other.get(0));
    }
  
    public String toString() {
        String ret = "("+this.array[0].toString();
        for(int i = 1; i < array.length; i++) {
            ret += ", " + this.array[i].toString();
        }
        ret += ")\n";
        return ret;
    }
    
}
